﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ErrorLevel - 定义 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="ErrorLevel is a built-in variable that is set to indicate the success or failure of some of the functions." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>

<body>
<h1>ErrorLevel</h1>

<p>This is a built-in variable that is set to indicate the success or failure of some of the built-in functions (not all built-in functions change the value of ErrorLevel). A value of 0 usually indicates success, and any other value usually indicates failure. You can also set the value of ErrorLevel yourself.</p>
<p>Each <a href="Threads.htm">thread</a> starts with an ErrorLevel of 0 and retains its own value of ErrorLevel, meaning that if the <a href="Threads.htm">current thread</a> is interrupted by another, when the original thread is resumed it will still have its original value of ErrorLevel, not the ErrorLevel that may have been set by the interrupting thread.</p>
<p>Although ErrorLevel typically contains a number (most often 0 or 1), the script can assign other types of values to it.</p>
<p class="note"><strong>Note</strong>: Since some built-in functions set ErrorLevel to values higher than 1, it is best not check whether ErrorLevel is 1, but instead whether ErrorLevel is not zero.</p>
<p>The following list contains all functions which set ErrorLevel, including the possible ErrorLevel values:</p>
<table class="info">
    <tr><td><a href="../commands/Control.htm">Control functions</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DirCopy.htm">DirCopy</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DirCreate.htm">DirCreate</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DirDelete.htm">DirDelete</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DirMove.htm">DirMove</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DirSelect.htm">DirSelect</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Download.htm">Download</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Drive.htm">Drive functions</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/EnvSet.htm">EnvSet</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileAppend.htm">FileAppend</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileCopy.htm">FileCopy</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileCreateShortcut.htm">FileCreateShortcut</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileDelete.htm">FileDelete</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileGetAttrib.htm">FileGetAttrib</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetShortcut.htm">FileGetShortcut</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetSize.htm">FileGetSize</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetTime.htm">FileGetTime</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetVersion.htm">FileGetVersion</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileInstall.htm">FileInstall</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileMove.htm">FileMove</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileRead.htm">FileRead</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRecycle.htm">FileRecycle</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRecycleEmpty.htm">FileRecycleEmpty</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileSelect.htm">FileSelect</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileSetAttrib.htm">FileSetAttrib</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileSetTime.htm">FileSetTime</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/GroupActivate.htm">GroupActivate</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Hotkey.htm">Hotkey</a></td><td>0, 1, 2, 3, 4, 5, 6, 98, 99</td></tr>
    <tr><td><a href="../commands/IniDelete.htm">IniDelete</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/IniRead.htm">IniRead</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/IniWrite.htm">IniWrite</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Input.htm">Input</a></td><td>NewInput, Max, Timeout, Match, EndKey:Name</td></tr>
    <tr><td><a href="../commands/InputBox.htm">InputBox</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/MenuSelect.htm">MenuSelect</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/PostMessage.htm">PostMessage</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/SendMessage.htm">SendMessage</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegDelete.htm">RegDelete</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegDeleteKey.htm">RegDeleteKey</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegRead.htm">RegRead</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegWrite.htm">RegWrite</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/SetWorkingDir.htm">SetWorkingDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Sort.htm#unique">Sort: U option</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/SoundGet.htm">SoundGet</a></td><td>0, <em>string</em></td></tr>
    <tr><td><a href="../commands/SoundPlay.htm">SoundPlay</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/SoundSet.htm">SoundSet</a></td><td>0, <em>string</em></td></tr>
    <tr><td><a href="../commands/StatusBarGetText.htm">StatusBarGetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/StatusBarWait.htm">StatusBarWait</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/WinGetText.htm">WinGetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetAlwaysOnTop.htm">WinSetAlwaysOnTop</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinMoveBottom.htm">WinMoveBottom</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinMoveTop.htm">WinMoveTop</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetEnabled.htm">WinSetEnabled</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinRedraw.htm">WinRedraw</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetStyle.htm">WinSetStyle / WinSetExStyle</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetRegion.htm">WinSetRegion</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetTransparent.htm">WinSetTransparent</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSetTransColor.htm">WinSetTransColor</a></td><td>0, 1</td></tr>
</table>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Focused := ControlGetFocus("Untitled - Notepad")
if ErrorLevel  <em>; i.e. it's not blank or zero.</em>
    MsgBox "The target window doesn't exist."
else
    MsgBox "Control with focus = " Focused</pre>
</div>
</body>
</html>